from wx.lib import ogl
import wx
DIG_IN = 1

ST_Digital = 0
ST_Analog  = 1
ST_Virtual = 2
ST_POWER   = 4

Gmin = 1e-7
Gmax = 1000
Rmax = 1.0 / Gmin
Rmin = 1.0 / Gmax
Vmax = 5.0
Vmin = 0.0

class tDevice :
    Container = None
    def __init__(self):
        
        self.Simulation_Type = ST_Digital
        
        self.Color_On = "#FF0000"
        self.Color_Off = "#C0C0C0"
        self.Size = (30,30);
        self.x = 100
        self.y = 100
        
        self.On = True
        self.shape = None
        self.pins =  {}
        # Create the hardware IO pins for the real simulation
        N = 100
        self.V = N * [0.0]
        self.G = N * [0.0]
        self.C = N * [0]
        self.T = N * [ DIG_IN ]
        self.NodeNr = N * [0] # OCA was -1
        for key in self.pins.keys():
          self.T [ key ] = self.pins [key][1]
          self.V [ key ] = self.pins [key][3]
          if self.pins [key][4] < Rmin:
            self.G [ key ] = 1.0 / self.pins [key][4]
          else:
            self.G [ key ] = Gmax
        
    def _Redraw (self):
        if self.On:
          """
          # to repaint the "ON", we use a little trick
          # flash paints double, so it will always be visible in front
          self.shape.SetBrush ( wx.Brush ( self.Color_On ) )
          self.shape.Flash()
          """
          # the OFF state is drawn in the official way
          dc = wx.ClientDC ( tDevice.Container )
          tDevice.Container.PrepareDC ( dc )
          self.shape.SetBrush ( wx.Brush ( self.Color_On ) )
          tDevice.Container.Redraw ( dc )
        else:
          
          dc = wx.ClientDC ( tDevice.Container )
          tDevice.Container.PrepareDC ( dc )
          self.shape.SetBrush ( wx.Brush ( self.Color_Off ) )
          tDevice.Container.Redraw ( dc )


